/*
** Interface to Musashi 68000 emulator for SMSE2K
** by unknownfile, 2009
*/

#include "smse2kincludes.h"
#include "m68000/m68kcpu.h"
#include "MusashiIntf.h"
#include "CPUFactory.h"

int CM68000::Exec(int cycles) {
	return m68k_exec(cpu, cycles);
}

void CM68000::Reset() {
	m68k_reset(cpu);
}

void CM68000::AssignMMU(int slot, CBaseMMU* mmu) {
	cpu->memory.mmu = mmu;
}

void CM68000::Interrupt(int line, int state) {
	m68k_set_irq_line(cpu,line,state);

}

void CM68000::Interrupt(int line, int state, int vector) {
	m68k_set_irq_line(cpu,line,state);
}


// Callbacks

void CM68000::HookM68KEventListener(IM68KEventListener* listener) {
	this->event_listener = listener;
	cpu->event_listener = this;
}

void CM68000::M68K_BkptAck(UINT32 data) {
	if (event_listener) event_listener->M68K_BkptAck(this, data);
}
void CM68000::M68K_Cmpild(UINT32 data, UINT8 reg) {
	if (event_listener) event_listener->M68K_Cmpild(this, data, reg);
}
void CM68000::M68K_IrqAck() {
	if (event_listener) event_listener->M68K_IrqAck(this);
}
void CM68000::M68K_ResetAck() {
	if (event_listener) event_listener->M68K_ResetAck(this);
}
void CM68000::M68K_Rte() {
	if (event_listener) event_listener->M68K_Rte(this);	
}
int CM68000::M68K_Tas() {
	if (event_listener) return event_listener->M68K_Tas(this);
	else return 0;
}

/************************************************************
		Init calls (overridden by various classes)
************************************************************/
int CM68000::Init(int clock) {
	this->clock = clock;

	this->cpu = m68000_init();
	if (!cpu) {
		Msg("No CPU core came back from Musashi, dying\n");	
		return 1;
	}

	return 0;
}

// CPU Factories
CPU_FACTORY("M68000",1,CM68000);